package com.suthund.controller;

import com.alibaba.fastjson.JSONObject;
import com.suthund.bean.ManagerPO;
import com.suthund.bean.response.BaseResponse;
import com.suthund.bean.response.JsonResponse;
import com.suthund.service.ManagerService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * manager api
 * Created by Lenovo on 2017/4/18.
 */
@RestController
@RequestMapping("/manager")
public class ManageController {

    @Resource
    private ManagerService managerService;

    @RequestMapping("add")
    public JsonResponse addManage(@RequestBody ManagerPO managerPO) {
        managerPO = managerService.addManager(managerPO);
        return JsonResponse.R_200(JSONObject.parseObject(JSONObject.toJSONString(managerPO)));
    }

    @RequestMapping("/queryAll")
    public BaseResponse queryAllManager() {
        return BaseResponse.ResponseSucc(managerService.findAll());
    }

    @RequestMapping("query/{managerId}")
    public BaseResponse queryByManagerId(@PathVariable Integer managerId) {
        ManagerPO managerPO = managerService.findById(managerId);
        return BaseResponse.ResponseSucc("查询成功", managerPO);
    }

    @RequestMapping("delete/{managerId}")
    public BaseResponse deleteManager(@PathVariable(value = "managerId") Integer managerId) {
        managerService.deleteManager(managerId);
        return BaseResponse.ResponseSucc("删除成功！");
    }

}
